import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    navBar:{
      navBarList:['视频管理-video'], //把导航菜单以数组的形式存储起来,并放入vuex里面，默认第一个选项。
      keepAliveList:['content-video'], //用于存储keep-alive需要缓存的组件的name。
      navBarActionName:'视频管理-video'  //导航菜单活动项名称,默认第一个选项。
    },
    token:{
      test1:'1616116'
    }
  },
  mutations: {
    pushNavBarList(state,date){ //注意！！vuex中使用数组、Map、Set等结构存储的时候，一定要用push、set、add等方法，直接赋值是不能动态渲染的！！
      if(!state.navBar.navBarList.includes(date)){
        state.navBar.navBarList.push(date);
      }
    },
    removeNavBarList(state,date){
      if(state.navBar.navBarList.includes(date)){
        state.navBar.navBarList.splice(state.navBar.navBarList.indexOf(date),1);
      }
    },
    pushKeepAliveList(state,date){
      if(!state.navBar.keepAliveList.includes(date)){
        state.navBar.keepAliveList.push(date);
      }
    },
    removeKeepAliveList(state,date){
      if(state.navBar.keepAliveList.includes(date)){
        state.navBar.keepAliveList.splice(state.navBar.keepAliveList.indexOf(date),1);
      }
    },
    setNavBarActionName(state,date){
      state.navBar.navBarActionName = date;
    }
  },
  actions: {
    pushNavBarList(context,data){
      context.commit('pushNavBarList',data);
    },
    removeNavBarList(context,data){
      context.commit('removeNavBarList',data);
    },
    pushKeepAliveList(context,data){
      context.commit('pushKeepAliveList',data);
    },
    removeKeepAliveList(context,data){
      context.commit('removeKeepAliveList',data);
    },
    setNavBarActionName(context,name){
      context.commit('setNavBarActionName',name);
    }
  }
})
